package at.fhooe.mc.duel_game.activities;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import at.fhooe.mc.duel_game.BackgroundSoundService;
import at.fhooe.mc.duel_game.GameLogic;
import at.fhooe.mc.duel_game.R;

public class MainMenuActivity extends Activity implements OnClickListener
{
	static Intent svc;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_main_menu);
		
		Button b1 = (Button) findViewById(R.id.ButtonStartGame);
		b1.setOnClickListener(this);
		Button b2 = (Button) findViewById(R.id.buttonHelp);
		b2.setOnClickListener(this);
		Button b3 = (Button) findViewById(R.id.ButtonExit);
		b3.setOnClickListener(this);
		
		svc = new Intent(this, BackgroundSoundService.class);
		startService(svc); //OR stopService(svc); 
	}
	
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		
		if(svc != null)
			stopService(svc);
	
		if(GameLogic.getInstance().getBluetoothService() != null)
			GameLogic.getInstance().getBluetoothService().stop();
	}
	
	public void onClick(View v)
	{
		
		switch (v.getId())
		{
			case R.id.ButtonStartGame:
				Intent intent = new Intent(getApplicationContext(), GameMenuActivity.class);
				startActivity(intent);
				break;
			case R.id.buttonHelp:
				Toast toast = Toast.makeText(this.getApplicationContext(), "Help yourself!", Toast.LENGTH_SHORT);
				toast.show();
				break;
			
			case R.id.ButtonExit:
				finish();
				break;
		}
	}
}